package com.servlet;

import com.dao.imp.FindOrder;
import com.entity.Order;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Mathison
 * @Title: ${NAME}
 * @Package: ${PACKAGE_NAME}
 * @Description: TODO
 * @date 2021/11/30 11:30
 **/

@WebServlet(name = "GetOrderListServlet", value = "/GetOrderListServlet")
public class GetGoodListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        int choosePageNum = Integer.parseInt(request.getParameter("pageNum"));
        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
        int realStartIndex = (choosePageNum-1)*pageSize;


        String selectSQL = "SELECT * FROM orders WHERE isPay = 1 ORDER BY `order_id` LIMIT "+realStartIndex+","+pageSize;

        System.out.println(selectSQL);

        List<Order> orderList = FindOrder.getOrderList(selectSQL);

//        System.out.println(orderList);
        JSONArray json = JSONArray.fromObject(orderList);
        response.getWriter().print(json);
    }
}
